package com.wkr.order.service;

import com.alibaba.fastjson.JSON;
import com.wkr.common.AppException;
import com.wkr.common.CommonResponse;
import com.wkr.common.Constants;
import com.wkr.order.feignclient.OrderFeignClient;
import com.wkr.order.feignclient.StoreFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ConsumerService {

    @Autowired
    OrderFeignClient orderFeignClient;
    @Autowired
    StoreFeignClient storeFeignClient;

    public void purchase(boolean ex) {
        CommonResponse<Boolean> orderResult = orderFeignClient.createTrainOrder();
        CommonResponse<Boolean> storeResult = storeFeignClient.updateTrainStore();
        log.info(JSON.toJSONString(orderResult));
        log.info(JSON.toJSONString(storeResult));
        if (!orderResult.getCode().equals(Constants.SUCCESS_CODE)) {
            throw new AppException("-1", "服务异常");
        }
        if (!storeResult.getCode().equals(Constants.SUCCESS_CODE)) {
            throw new AppException("-1", "服务异常");
        }
        try {
            if (ex) {
                int a = 10 / 0;
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new AppException("-1", e.getMessage());
        }

    }
}
